﻿#include "MyTreeView.h"
#include <QMouseEvent>
#include <QDebug>

MyTreeView::MyTreeView(QWidget *parent)
        : QTreeView(parent)
{

}

void MyTreeView::mousePressEvent(QMouseEvent *event)
{
    qDebug()<<"mousePressEvent";
    //实现点空白处取消选择
    QPoint p = event->pos();
    QModelIndex index = indexAt(p);
    if(!index.isValid())
    {
        setCurrentIndex(QModelIndex());
        return;
    }

    //调用基类的点击处理，不然点击的原有响应也失效了
    //但如果就想禁用tree控件单击，不调用即可
    QTreeView::mousePressEvent(event);
}

void MyTreeView::mouseReleaseEvent(QMouseEvent *event)
{
    qDebug()<<"mouseReleaseEvent";
    //你的特殊处理代码
    //...


    QTreeView::mouseReleaseEvent(event);
}

void MyTreeView::mouseDoubleClickEvent(QMouseEvent *event)
{
    qDebug()<<"mouseDoubleClickEvent";
    //你的特殊处理代码
    //...


    QTreeView::mouseDoubleClickEvent(event);
}

void MyTreeView::mouseMoveEvent(QMouseEvent *event)
{
    qDebug()<<"mouseMoveEvent";
    //你的特殊处理代码
    //...


    QTreeView::mouseMoveEvent(event);
}

void MyTreeView::keyPressEvent(QKeyEvent *event)
{
    qDebug()<<"keyPressEvent";
    //你的特殊处理代码
    //...


    QTreeView::keyPressEvent(event);
}
